package com.bite.book.mapper;

import com.bite.book.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BookMapper {

    //添加图书
    @Insert("INSERT INTO book_info (book_name,author,`count`,price,publish,`status`) " +
            "VALUES (#{bookName},#{author},#{count},#{price},#{publish},#{status}) ")
    Integer insertBook(BookInfo bookInfo);

    //图书列表 要返回两个数据  一个是总个数，另一个是该页的数据      COUNT(1)是返回所有行的数量
    @Select("select count(1) from book_info where status != 0")
    Integer count();
    //offset 起始  limit 多少条数据
    @Select("select  * from book_info where status != 0 order by id desc limit #{offset},#{limit}")
    List<BookInfo> getListByPage(Integer offset,Integer limit);


    //查找图书
    @Select("select * from book_info where id = #{bookId}")
    BookInfo getBookInfo(Integer bookId);

    //修改图书信息   动态SQL
    Integer updateBook(BookInfo bookInfo);

    //批量删除
    Integer batchDelete(List<Integer> ids);
}
